##########################################################################################
# 
# Replication Materials for:
#
# Carlo Koos & Richard Traunmüller
# "The Gendered Costs of Stigma: 
# How Experiences of Conflict-related Sexual Violence Encourage Civic Engagement
# for Women and Men" American Journal of Political Science
#
# Author: Richard Traunmüller
# Date: 18.08.2023
# Contact: traunmueller@uni-mannnheim.de
#
############################################################################################
# All analyses were run using:

- R version 4.1.2 
- MacOS version 11.4

############################################################################################
# The replication materials include:

# Read me file

- "README.txt" 

# R Code 
# Master code file:

- "ajps_replication_master.R" 

# The "Code" folder includes:

- "ajps_replication_create_variables.R"- "ajps_replication_direct_items.R"- "ajps_replication_figure_1.R"- "ajps_replication_figure_2.R"- "ajps_replication_figure_3.R"- "ajps_replication_figure_G1.R"- "ajps_replication_figure_I4.R"- "ajps_replication_gender_specific_models_do_not_run_MCMC.R"- "ajps_replication_gender_specific_models.R"- "ajps_replication_interethnic.R"- "ajps_replication_list_experiments.R"- "ajps_replication_main_models.R"- "ajps_replication_PTG.R"
- "ajps_replication_sensitivity_nondisclosure_do_not_run_simulations.R"- "ajps_replication_sensitivity_nondisclosure.R"- "ajps_replication_sensitivity_unobserved_confounding.R"


# The "Data" folder includes:
# Datasets

- "ajps_replication_data_congo.RData"
- "ajps_replication_data_liberia.RData"
- "ajps_replication_data_srilanka.RData"

# MCMC output

- "lib_out_m.rds"
- "lib_out_f.rds"

# Simulation output

- "sim.coefs.congo.rds"
- "sim.coefs.liberia.rds"
- "sim.coefs.sri.rds"

# The "Codebooks" folder includes:

- "Codebook Congo Data Set.pdf"
- "Codebook Liberia Data Set.pdf"
- "Codebook Sri Lanka Data Set.pdf"

# R package "bayeslist"

- "bayeslist_0.0.1.1.tar.gz"

# Log files
- "ajps_replication_log_file.Rmd"
- "ajps_replication_log_file.Rmd"

############################################################################################
# To replicate all results, tables and figures simply run this master code file:
# (Make sure you specify YOURPATH in the master file correctly.)

- "ajps_replication_master.R" 

# The gender-specific models for Liberia rely on Bayesian estimation using MCMC. This takes 
# quite a while. (Don't worry - grab a cup of coffee.)
# Note that you can also replicate the results without having to re-run the Bayesian models.
# To do this, simply change the following in the master file:

1. Comment out line 190 in the master code file to not run: 
- "ajps_replication_gender_specific_models.R"

2. Un-comment line 193 to run: 
- "ajps_replication_gender_specific_models_do_not_run_MCMC.R"


# The sensitivity analysis for the "no non-disclosure" assumption relies on simulation. This takes 
# quite a while. (Don't worry - come back the next day.)
# Note that you can also replicate the results without having to re-run the simulations.
# To do this, simply change the following in the master file:

1. Comment out line 342 in the master code file to not run: 
- "ajps_replication_sensitivity_nondisclosure.R"

2. Un-comment line 345 to run: 
- "ajps_replication_sensitivity_nondisclosure_do_not_run_simulations.R"


############################################################################################
# Make sure you have the following R packages installed before running the master code file:

install.packages("list")
install.packages("psych")
install.packages("arm")
install.packages("misreport")
install.packages("stargazer")
install.packages("bayeslist") # Needs to be installed manually! See below for instructions.
install.packages("xtable")
install.packages("denstrip")

############################################################################################
# To install the "bayeslist" package run the following lines of code:
# (Please note that the installation may take quite a while! Don't worry, grab a coffee.)

install.packages("RTools")
install.packages("rstantools")
install.packages("rstan")

install.packages("YOURPATH/AJPS_replication_materials/bayeslist_0.0.1.1.tar.gz", repos=NULL, type='source')

# For methodological background see Xiao Lu & Richard Traunmüller (2021): Improving Studies of 
# Sensitive Topics Using Prior Evidence: A Unified Bayesian Framework for List Experiments. 
# SSRN Workin Paper Series 3871089

############################################################################################

# END